<nz-card nzTitle="加价券信息">
  <nz-descriptions
    nzBordered
    nzSize="small"
    class="detail-infos"
    [nzColumn]="{ xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }"
  >
    <nz-descriptions-item nzTitle="加价券类型">
      {{ detailDatas.type === 1 ? '满加券' : '百分比券' }}
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="加价券名称">
      {{ detailDatas.name || '-' }}
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="备注">
      {{ detailDatas.remark || '-' }}
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="总数量">
      {{ detailDatas.total || '0' }}
    </nz-descriptions-item>

    <nz-descriptions-item nzTitle="加价条件">
      单台机器回收价满 {{ detailDatas?.orderLimitMoney || '--' }} 元，加价 {{ detailDatas?.limitSmall || '--' }}
      <span *ngIf="detailDatas.type === 2">%</span>
      <span *ngIf="detailDatas.type === 1">元</span>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="最高加价金额" *ngIf="detailDatas?.type === 2">
      {{ detailDatas?.limitBig || '0' }} 元
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="适用用户">
      <div [ngSwitch]="detailDatas.userType">
        <div *ngSwitchCase="0">
          <nz-tag>通用</nz-tag>
        </div>
        <div *ngSwitchCase="1">
          <nz-tag [nzColor]="'#87d068'">C端</nz-tag>
        </div>
        <div *ngSwitchCase="2">
          <nz-tag [nzColor]="'#2db7f5'">B端</nz-tag>
        </div>
        <div *ngSwitchDefault>-</div>
      </div>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="适用成色">
      <div [ngSwitch]="detailDatas.applyColour">
        <div *ngSwitchCase="1">二手</div>
        <div *ngSwitchCase="2">准新</div>
        <div *ngSwitchDefault>全部</div>
      </div>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="适用机型">
      <ng-container *ngIf="detailDatas?.containsModel == 0;else templateModel">
        全部
      </ng-container>
      <ng-template #templateModel>
        {{ strToArray(detailDatas?.containsModel) }} 个机型
        <button
          nz-button
          nzType="link"
          nzSize="small"
          (click)="selectMoreModel()"
        >查看</button>

        <!-- 机型select-tree -->
        <model-select-tree
          [(ngModel)]="isModelVisible"
          [defaultKeys]="defaultModelKeys"
          [disabled]="true"
        ></model-select-tree>
      </ng-template>
    </nz-descriptions-item>

    <nz-descriptions-item nzTitle="前端展示">
      <span [ngStyle]="{'color': detailDatas?.isShowWeb === 0 ? '#F56C6C' : ''}">
        {{ detailDatas.isShowWeb === 0 ? '不展示' : '展示' }}
      </span>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="有效期" [nzSpan]="2">
      <ng-container *ngIf="detailDatas?.limitTimeNum == -1;else templateYxq">
        {{ detailDatas?.useBeginTime || '----' }} ~ {{ detailDatas?.useEndTime || '----' }}
      </ng-container>
      <ng-template #templateYxq>
        获得后{{ detailDatas?.limitTimeNum == 0 ? '当' : detailDatas?.limitTimeNum }}天内有效
      </ng-template>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="规则说明" [nzSpan]="3">
      {{ detailDatas?.useDesc || '-' }}
    </nz-descriptions-item>
  </nz-descriptions>
</nz-card>

<nz-card nzTitle="使用统计" class="m-t-4">
  <nz-descriptions
    nzBordered
    nzSize="small"
    class="detail-infos"
    [nzColumn]="{ xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }"
  >
    <nz-descriptions-item nzTitle="总数量">{{ useCouponInfos?.total || '0' }}</nz-descriptions-item>
    <nz-descriptions-item nzTitle="已领取">
      {{ useCouponInfos?.userGetCount || '0' }}
      <a
        nz-button
        nzType="link"
        nzSize="small"
        target="_blank"
        [routerLink]="['/aisi-recyc/loveUserMakeupCoupon']"
        [queryParams]="{couponNo: detailDatas.no}"
      >查看</a>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="下单数量">{{ useCouponInfos?.placeOrderCount || '0' }}</nz-descriptions-item>
    <nz-descriptions-item nzTitle="成交订单数">{{ useCouponInfos?.dealOrderCount || '0' }}</nz-descriptions-item>

    <nz-descriptions-item nzTitle="回收机器">{{ useCouponInfos?.machineCount || '0' }}</nz-descriptions-item>
    <nz-descriptions-item nzTitle="总成交金额">{{ useCouponInfos?.tprcSum || '0' }} 元</nz-descriptions-item>
  </nz-descriptions>
</nz-card>

<nz-card nzTitle="使用记录" [nzExtra]="extraTemplate" class="m-t-4">
  <ng-template #extraTemplate>
    <!-- <div class="common-search-wrap">
      <div class="common-search-forms">
        <div class="common-form-item">
          <label class="common-search-label">订单状态</label>
          <div class="common-search-conrol">
            <nz-select
              nzShowSearch
              nzAllowClear
              nzPlaceHolder="全部"
              [(ngModel)]="orderTableParams.state"
              (ngModelChange)="statusChange($event)">
              <nz-option
                *ngFor="let o of orderStateOptions"
                [nzLabel]="o.label"
                [nzValue]="o.id"
              ></nz-option>
            </nz-select>
          </div>
        </div>
      </div>
    </div> -->
  </ng-template>

  <div class="table-wrap">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzOuterBordered
      [nzScroll]="{ x: '1100px' }"
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="orderTableParams.loading"
      [nzData]="orderTableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="orderTableParams.total"
      [nzPageIndex]="orderTableParams.page"
      [nzPageSize]="orderTableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
    >
      <thead>
        <tr>
          <th nzAlign="center" nzWidth="220px" nzLeft>订单编号</th>
          <th nzAlign="center" nzWidth="250px">平台渠道</th>
          <th nzAlign="center" nzWidth="120px">订单状态</th>
          <th nzAlign="center" nzWidth="120px">用户身份</th>
          <th nzAlign="center" nzWidth="180px">下单机型</th>
          <th nzAlign="center" nzWidth="170px">预估合计</th>
          <th nzAlign="center" nzWidth="170px">验机合计</th>
          <th nzAlign="center" nzWidth="150px">验机结果</th>
          <th nzAlign="center" nzWidth="170px">下单时间</th>
          <th nzAlign="center" nzWidth="170px">揽件时间</th>
          <th nzAlign="center" nzWidth="170px">到货签收时间</th>
          <th nzAlign="center" nzWidth="170px">成交时间</th>
          <th nzAlign="center" nzWidth="170px">更新时间</th>
          <th nzAlign="center" nzWidth="150px" nzRight>操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <!-- 订单编号 -->
          <td nzAlign="center" nzLeft>{{ data.okey || '-' }}</td>
          <!-- 平台渠道 -->
          <td nzAlign="center">
            <!-- 平台 & 身份 -->
            <div>
              <ng-container *ngIf="data.platform;else templatePlatform">
                <nz-tag [nzColor]="'blue'">
                  {{ filterPlatform(data.platform) }}
                </nz-tag>
              </ng-container>
              <ng-template #templatePlatform>-</ng-template>

              <ng-container>
                <nz-tag [nzColor]="'#2db7f5'" *ngIf="data?.userType == 2">B端</nz-tag>
                <nz-tag [nzColor]="'#87d068'" *ngIf="data?.userType == 1">C端</nz-tag>
              </ng-container>
            </div>
            <!-- 推广渠道 cid -->
            <div class="p-t-5">
              <ng-container *ngFor="let extension of extensionOptions">
                <nz-tag
                  *ngIf="extension.content == data.cid"
                  nzColor="success">
                  {{ extension.name }}
                </nz-tag>
              </ng-container>
            </div>
          </td>
          <!-- 订单状态 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.ostat | orderState: 'color'}">
              {{ data.ostat | orderState: 'text' }}
            </span>
          </td>
          <!-- 用户身份 -->
          <td nzAlign="center">
            <ng-container *ngIf="data.userId;else templateUser">
              <a
                nz-button
                nzType="link"
                nzSize="small"
                [routerLink]="['/customer/tabs', data.userId, 0]"
                target="_blank"
              >{{ data.userId }}</a>
            </ng-container>
            <ng-template #templateUser>
              游客
            </ng-template>
          </td>
          <!-- 下单机型 -->
          <td nzAlign="center">{{ data?.umname || '-' }}</td>
          <!-- 预估合计 -->
          <td nzAlign="center">
            {{ (data.uprc || 0) + (data.orderAprc || 0) + (data.cprc || 0) }}
            <span *ngIf="data.orderAprc || data.cprc">（含加价{{ (data.orderAprc || 0) + (data.cprc || 0) }}）</span>
          </td>
          <!-- 验机合计 -->
          <td nzAlign="center">
            <p [ngStyle]="{'color': ((data.bprc || 0) + (data.aprc || 0)) < ((data.uprc || 0) + (data.orderAprc || 0)) ? '#FF0000' : ''}">
              {{ (data.bprc || 0) + (data.aprc || 0) + (data.cprc || 0) }}
              <span *ngIf="data.aprc || data.cprc">（含加价{{ (data.aprc || 0) + (data.cprc || 0) }}）</span>
            </p>
          </td>
          <!-- 验机结果 -->
          <td nzAlign="center">
            {{ data.restype | machineResult }}
          </td>
          <!-- 下单时间 -->
          <td nzAlign="center">
            {{ data.otime11 || '-' }}
          </td>
          <!-- 揽件时间 -->
          <td nzAlign="center">
            {{ data.otime13 || '-' }}
          </td>
          <!-- 到货签收时间 -->
          <td nzAlign="center">
            {{ data.otime14 || '-' }}
          </td>
          <!-- 成交时间 -->
          <td nzAlign="center">
            {{ data.otime19 || '-' }}
          </td>
          <!-- 更新时间 -->
          <td nzAlign="center">
            {{ data.updateTime || '-' }}
          </td>
          <!-- 操作 -->
          <td nzAlign="center" nzRight>
            <a
              nz-button
              nzType="link"
              nzSize="small"
              target="_blank"
              [routerLink]="['/aisi-recyc/loveOrderDetails']"
              [queryParams]="{id: data.id}"
            >查看</a>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>

<!-- Modal 爱思用户信息 -->
<app-user-info-modal #userInfoRef [userId]="modalUserId"></app-user-info-modal>